package com.drinks.yiniang.adapter.photo;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.base.BaseQuickRCVAdapter;
import com.drinks.yiniang.common.camera.album.Result;
import com.drinks.yiniang.entity.photo.Photos;
import com.drinks.yiniang.utils.GlideUtils;
import com.hansen.library.ui.widget.image.PressedImageView;
import com.hansen.library.ui.widget.image.RatioRoundImageView;

import java.util.List;

import static com.drinks.yiniang.entity.photo.Photos.TYPE_ITEM_PHOTO_ALBUM_PHOTO;
import static com.drinks.yiniang.entity.photo.Photos.TYPE_ITEM_PHOTO_ALBUM_TITLE;
import static com.drinks.yiniang.entity.photo.Photos.TYPE_ITEM_PHOTO_DRAFTS;

/**
 * 草稿adapter
 * @author han
 * @date 2019/8/30
 */
public class DraftsPhotosAdapter extends BaseQuickRCVAdapter<Photos, BaseViewHolder> {

    public DraftsPhotosAdapter(Context mContext, @Nullable List<Photos> data) {
        super(R.layout.item_album_photo_drafts, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Photos item) {
        GlideUtils.load(mContext, (RatioRoundImageView) helper.getView(R.id.iv_album_photos_drafts), item.path);

        updateSelector((TextView) helper.getView(R.id.tv_album_photos_drafts_choose), item);

        setChooseClick(helper.getView(R.id.v_album_photos_drafts_choose), item, helper.getAdapterPosition());
    }

    private void updateSelector(TextView tvSelector, Photos photo) {
        if (photo.isChecked) {
            tvSelector.setBackgroundResource(R.mipmap.icon_photo_choose_p);
        } else {
            tvSelector.setBackgroundResource(R.mipmap.icon_photo_choose_n);
        }
    }

    private void setChooseClick(View v, final Photos photo, final int position) {
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                photo.isChecked = !photo.isChecked;

                setData(position, photo);
            }
        });
    }
}
